﻿using System.Collections.Generic;
using System.Windows.Forms;
using AnimatorNS;
using Sunny.UI;

namespace DevelopTool.Common
{
    /// <summary>
    /// 动画帮助类
    /// </summary>
    public class AnimatorHelper
    {
        /// <summary>
        /// 给窗体绑定动画
        /// </summary>
        /// <param name="form"></param>
        public static void BindAnimator(Form form)
        {
            var allControls = form.GetAllControls();
            foreach (Control control in allControls)
            {
                control.Visible = false;

                int idx = RandomEx.Next((int)AnimationType.VertRevSlide);
                AnimationType type = (AnimationType)(idx++);
                Sunny.UI.AnimatorHelper.Instance.SetAnimationType(type).Show(control);
                // AnimatorHelper.Instance.WaitAllAnimations();
            }
        }

        /// <summary>
        /// 绑定显示动画
        /// </summary>
        /// <param name="controls"></param>
        public static void BindShowAnimator(List<Control> controls)
        {
            foreach (Control control in controls)
            {
                if (control == null) continue;

                if (!control.Enabled) continue;//忽略禁用控件

                control.Hide();//先隐藏控件

                int idx = RandomEx.Next((int)AnimationType.VertRevSlide);
                AnimationType type = (AnimationType)(idx++);
                Sunny.UI.AnimatorHelper.Instance.SetAnimationType(type).Show(control);
                // AnimatorHelper.Instance.WaitAllAnimations();
            }
        }

        /// <summary>
        /// 绑定隐藏动画
        /// </summary>
        /// <param name="controls"></param>
        public static void BindHideAnimator(List<Control> controls)
        {
            foreach (Control control in controls)
            {
                if (!control.Enabled) continue;//忽略禁用控件

                control.Show();//先显示控件

                int idx = RandomEx.Next((int)AnimationType.VertRevSlide);
                AnimationType type = (AnimationType)(idx++);
                Sunny.UI.AnimatorHelper.Instance.SetAnimationType(type).Hide(control);
                // AnimatorHelper.Instance.WaitAllAnimations();
            }
        }

    }
}
